import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home/Home.vue";

Vue.use(Router);

export default new Router({
  // mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "home",
      component: Home,
      meta: {
        title: "首页",
        keepAlive: true
      },
      children: [
        {
          path: "goods/:id",
          meta: {
            title: "商品"
          },
          component: () =>
            import(/* webpackChunkName: "goodsDetail" */ "./views/GoodsDetail/GoodsDetail.vue")
        }
      ]
    },
    {
      path: "/category",
      name: "Category",
      meta: {
        title: "分类",
        keepAlive: true
      },
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "category" */ "./views/Category/Category.vue")
    },
    {
      path: "/userCenter",
      name: "UserCenter",
      meta: {
        title: "我的", // 用户中心
        isLogin: true, //需要登录
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "userCenter" */ "./views/UserCenter/UserCenter.vue")
    },
    {
      path: "/search",
      name: "Search",
      meta: {
        title: "搜索", // 用户中心
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "search" */ "./views/Search/Search.vue")
    },
    {
      path: "/login",
      name: "Login",
      meta: {
        title: "登录",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "login" */ "./views/Login/Login.vue")
    },
    {
      path: "/shoppingCat",
      name: "ShoppingCat",
      meta: {
        title: "购物车",
        keepAlive: true
      },
      component: () =>
        import(/* webpackChunkName: "ShoppingCat" */ "./views/ShoppingCat/ShoppingCat.vue")
    },
    {
      path: "/goodsDetail/id/:id",
      name: "GoodsDetail",
      meta: {
        title: "商品详情"
      },
      component: () =>
        import(/* webpackChunkName: "goodsDetail" */ "./views/GoodsDetail/GoodsDetail.vue")
    }
  ]
});
